package com.wlanauth.web.util;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.hibernate.criterion.Restrictions;

import com.wlanauth.core.criteria.GeneralCriteria;
import com.wlanauth.core.criteria.GeneralCriteriaResult;
import com.wlanauth.domain.manage.SystemProperty;
/**
 * 系统属性工具类
 * @author zz
 * @date 2012-5-27
 * @email charles.zz.life@gmail.com
 */
public class SystemPropertyUtils {
	
	public static final String KEY_RADIUSRATIO = "RADIUS_RATIO";//计费比率
	public static final String KEY_OCTRULERATIO = "OCTRULE_RATIO";//流量规则比率
	
	
	private static Map<String,SystemProperty> propsMap = new ConcurrentHashMap<String,SystemProperty>();
	
	public static SystemProperty getProperty(String key){
		if(!propsMap.containsKey(key)){
			GeneralCriteria criteria = new GeneralCriteria(SystemProperty.class);
			criteria.setDataOnly(true);
			criteria.add(Restrictions.eq("key", key));
			GeneralCriteriaResult<SystemProperty> result = criteria.executeQuery();
			if(result.getData()!=null&&result.getData().size()>0){
				propsMap.put(key, result.getData().get(0));
			}
		}
		return propsMap.get(key);
	}
	public static void flushProperty(SystemProperty prop){
		propsMap.put(prop.getKey(), prop);
	}
}
